package com.example.demo.thread.executor;

import java.util.concurrent.*;

/**
 * @author luowj12
 * @since 2021/4/9 14:15
 */
public class ExecutorTest {

    private static ExecutorService executorService = new ThreadPoolExecutor(1,1,60, TimeUnit.SECONDS,
            new ArrayBlockingQueue(100));

    ExecutorService ex = new ThreadPoolExecutor(5, 8, 30, TimeUnit.SECONDS, new LinkedBlockingQueue<>(),
            new ThreadFactory(){
                @Override
                public Thread newThread(Runnable r) {
                    Thread thread = new Thread(r);
                    //thread.setUncaughtExceptionHandler(new MyUnchecckedExceptionhandler());
                    return thread;
                }}, new ThreadPoolExecutor.CallerRunsPolicy());

    private static ExecutorService executorService1 = Executors.newFixedThreadPool(5);

    private static ExecutorService executorService2 = Executors.newCachedThreadPool();

    private static ExecutorService executorService3= Executors.newSingleThreadExecutor();

    private static ScheduledExecutorService executorService4 = Executors.newSingleThreadScheduledExecutor();

    public static void main(String[] args) {
        ExecutorService fixedExecutorService = Executors.newFixedThreadPool(1);
        ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) fixedExecutorService;
        System.out.println(threadPoolExecutor.getMaximumPoolSize());
        threadPoolExecutor.setCorePoolSize(8);

        ExecutorService singleExecutorService = Executors.newSingleThreadExecutor();// 运行时异常 java.lang.ClassCastException// ThreadPoolExecutor threadPoolExecutor2 = (ThreadPoolExecutor) singleExecutorService;
    }

}
